home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Utils / Software6 / Product11 / foxytunes-1.1-fx+mz+tb.xpi / install.js next >
Text File  |  2004-12-27  |  6KB  |  176 lines

  1. const APP_DISPLAY_NAME = "FoxyTunes";
  2. const APP_VERSION = "1.1";
  3. const APP_SHORT_NAME = "foxytunes";
  4. const APP_AUTHOR = "iosart";
  5. const APP_PACKAGE = "/" + APP_AUTHOR + "/" + APP_SHORT_NAME;
  6. const APP_JAR_FILE = APP_SHORT_NAME + ".jar";
  7. const BLD_ID_MOZILLA_MIN = 20040101; // 1.6
  8. const APP_WHERE_MESSAGE = "Install " + APP_DISPLAY_NAME +
  9.                 " to your profile folder (OK) or to your program folder (Cancel) ?";
  10. const APP_BUILD_TOO_OLD = APP_DISPLAY_NAME + " " + APP_VERSION     +
  11.                 " must be installed to builds released after " +
  12.                 BLD_ID_MOZILLA_MIN + " !";
  13.  
  14. const APP_CONTENT_FOLDER = "content/";
  15. const APP_LOCALE_FOLDER     = "locale/";
  16. const APP_LOCALES      = ["en-US"];
  17. const APP_SKIN_FOLDER     = "skin/classic/";
  18.  
  19. const APP_COMPONENTS_FOLDER    = "components/";
  20. const XPT_FILE_NAME         = "FoxyTunes.xpt";
  21. const DLL_FILE_NAME         = "FoxyTunes.dll";
  22.  
  23. function verifyNoError(errorMessage) {
  24.     err = getLastError();
  25.  
  26.     if (err != SUCCESS) {
  27.         alert(errorMessage + " (" + err + ")");
  28.             cancelInstall(err);
  29.     }
  30.  
  31.     return err;
  32. }
  33.  
  34. function getPlatform() {
  35.     var platformStr;
  36.     if ('platform' in Install) {
  37.         platformStr = new String(Install.platform);
  38.         if (platformStr.search(/Windows/gi) != -1) {
  39.             return "windows";
  40.         }
  41.  
  42.         if (!platformStr.search(/Linux/gi) != -1) {
  43.             return "linux";
  44.         }
  45.  
  46.         if (!platformStr.search(/Mac/gi) != -1) {
  47.             return "mac";
  48.         }
  49.         }
  50.     return '';
  51. }
  52.  
  53. function platformSpecificInstall() {
  54.     var platform = getPlatform();
  55.  
  56.     var componentsDir = getFolder("Components"); 
  57.     
  58.     if (platform == 'windows') {
  59.         addFile(DLL_FILE_NAME, APP_VERSION, APP_COMPONENTS_FOLDER + DLL_FILE_NAME, componentsDir, "");  
  60.         if (verifyNoError("Couldn't install " + DLL_FILE_NAME) != SUCCESS) { return false; }
  61.         return true;
  62.     }
  63.  
  64.         var platformSpecificDllFileName = DLL_FILE_NAME + "." + platform;
  65.     addFile(DLL_FILE_NAME, APP_VERSION, APP_COMPONENTS_FOLDER + platformSpecificDllFileName, componentsDir, "");  
  66.     if (verifyNoError("Couldn't install " + platformSpecificDllFileName) != SUCCESS) { return false; }
  67.  
  68.     var file = getFolder("Components", platformSpecificDllFileName);     
  69.     if (verifyNoError("Couldn't get platform specific file: " + platformSpecificDllFileName) != SUCCESS) { return false; }
  70.  
  71.     if (!File.exists(file)) {
  72.         alert("Couldn't find platform specific file: " + platformSpecificDllFileName);
  73.             cancelInstall(err);
  74.         return false;
  75.     }
  76.  
  77.     // make the platform specific file the main dll:
  78.     File.rename(file, DLL_FILE_NAME);
  79.     if (verifyNoError("Couldn't rename platform specific file: " + platformSpecificDllFileName +
  80.                     " to " + DLL_FILE_NAME) != SUCCESS) { return false; }
  81.  
  82.     return true;
  83. }
  84.  
  85. function preinstallCleanup() {
  86.     initInstall("pre-install-cleanup", "/foxytunes-cleanup", "0.0"); 
  87.  
  88.     // remove old files if exist
  89.  
  90.     var oldFile = getFolder("Components", XPT_FILE_NAME);     
  91.     File.remove(oldFile);
  92.  
  93.     oldFile = getFolder("Components", DLL_FILE_NAME);     
  94.     File.remove(oldFile);
  95.  
  96.     performInstall(); 
  97. }
  98.  
  99. function perfromInstallation() {
  100.     var err;
  101.  
  102.     // verify that the Mozilla build is not too old
  103.     var currBuild = new String(buildID).substr(0, 8) - 0;
  104.     if (currBuild && currBuild < BLD_ID_MOZILLA_MIN) {
  105.        alert(APP_BUILD_TOO_OLD);
  106.           cancelInstall(INSTALL_NOT_STARTED);
  107.        return;
  108.     }
  109.  
  110.         initInstall(APP_DISPLAY_NAME, APP_SHORT_NAME, APP_VERSION);
  111.     if (verifyNoError("Couldn't init the installation process") != SUCCESS) { return; }
  112.  
  113.     // install chrome:
  114.     var where, chromef;
  115.     var inProfile = confirm(APP_WHERE_MESSAGE);
  116.     if (inProfile) {
  117.         chromef = getFolder("Profile", "chrome");
  118.         where = PROFILE_CHROME;
  119.        } else {
  120.         chromef = getFolder("chrome");
  121.         where = DELAYED_CHROME;
  122.        }
  123.  
  124.         addFile(APP_PACKAGE, APP_VERSION, "chrome/" + APP_JAR_FILE, chromef, null);
  125.     err = verifyNoError("Failed to create " + APP_JAR_FILE + "\n" +
  126.                     "You probably don't have appropriate permissions \n" +
  127.                     "(write access to " + (inProfile ? "profile" : "browser") + "/chrome directory). \n"); 
  128.     if (err != SUCCESS) { return; }
  129.  
  130.     var jar = getFolder(chromef, APP_JAR_FILE);
  131.  
  132.     registerChrome(CONTENT | where, jar, APP_CONTENT_FOLDER);
  133.     if (verifyNoError("Couldn't register " + APP_CONTENT_FOLDER + " folder") != SUCCESS) { return; }
  134.  
  135.       for (var iLocale=0; iLocale < APP_LOCALES.length; iLocale++) {
  136.          var localeFolder = APP_LOCALE_FOLDER + APP_LOCALES[iLocale] + "/";
  137.         registerChrome(LOCALE  | where, jar, localeFolder);
  138.         if (verifyNoError("Couldn't register " + localeFolder + " folder") != SUCCESS) { return; }
  139.       }
  140.  
  141.     registerChrome(SKIN    | where, jar, APP_SKIN_FOLDER);
  142.     if (verifyNoError("Couldn't register " + APP_SKIN_FOLDER + " folder") != SUCCESS) { return; }
  143.  
  144.     // install XPCOM components:
  145.     var componentsDir = getFolder("Components"); 
  146.  
  147.     addFile(XPT_FILE_NAME, APP_VERSION, APP_COMPONENTS_FOLDER + XPT_FILE_NAME, componentsDir, "");  
  148.     if (verifyNoError("Couldn't install " + XPT_FILE_NAME) != SUCCESS) { return; }
  149.  
  150.     if (!platformSpecificInstall()) {
  151.         return;
  152.     }
  153.           performInstall();
  154.  
  155.     err = getLastError();
  156.     if (err == SUCCESS) {
  157.             alert(APP_DISPLAY_NAME + " version " + APP_VERSION + " has been successfully installed to your " +
  158.                    (inProfile?"profile":"program") + " folder.\n\n" +
  159.                "Please, restart the browser before continuing!");
  160.           } else {
  161.         if (err == REBOOT_NEEDED) {
  162.             alert("Install failed because a previous version of " + 
  163.                     APP_DISPLAY_NAME + " has not been uninstalled.");
  164.         } else {
  165.             alert("Install failed! Error code:" + err);
  166.         }
  167.         cancelInstall(err);
  168.           }
  169. }
  170.  
  171. // perfrom some clean up before installing
  172. preinstallCleanup();
  173.  
  174. // Call the main installation function
  175. perfromInstallation();
  176.